home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / shells / tcshsrc.zoo / tcsh / ed.init.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-02-21  |  45.1 KB  |  1,672 lines

  1. /* $Header: /home/hyperion/mu/christos/src/sys/tcsh-6.00/RCS/ed.init.c,v 3.9 1991/08/06 01:45:29 christos Exp $ */
  2. /*
  3.  * ed.init.c: Editor initializations
  4.  */
  5. /*-
  6.  * Copyright (c) 1980, 1991 The Regents of the University of California.
  7.  * All rights reserved.
  8.  *
  9.  * Redistribution and use in source and binary forms, with or without
  10.  * modification, are permitted provided that the following conditions
  11.  * are met:
  12.  * 1. Redistributions of source code must retain the above copyright
  13.  *    notice, this list of conditions and the following disclaimer.
  14.  * 2. Redistributions in binary form must reproduce the above copyright
  15.  *    notice, this list of conditions and the following disclaimer in the
  16.  *    documentation and/or other materials provided with the distribution.
  17.  * 3. All advertising materials mentioning features or use of this software
  18.  *    must display the following acknowledgement:
  19.  *    This product includes software developed by the University of
  20.  *    California, Berkeley and its contributors.
  21.  * 4. Neither the name of the University nor the names of its contributors
  22.  *    may be used to endorse or promote products derived from this software
  23.  *    without specific prior written permission.
  24.  *
  25.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  26.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  27.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  28.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  29.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  30.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  31.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  32.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  33.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  34.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  35.  * SUCH DAMAGE.
  36.  */
  37. #include "config.h"
  38. RCSID("$Id: ed.init.c,v 3.9 1991/08/06 01:45:29 christos Exp $")
  39.  
  40. #include "sh.h"
  41. #define EXTERN            /* intern */
  42. #include "ed.h"
  43. #include "tc.h"
  44. #include "ed.defns.h"
  45.  
  46. #ifdef __MINT__
  47. extern int __mint;    /* version of MiNT we're running under */
  48. #endif
  49.  
  50. #if defined(TERMIO) || defined(POSIX)
  51. /*
  52.  * Aix compatible names
  53.  */
  54. # if defined(VWERSE) && !defined(VWERASE)
  55. #  define VWERASE VWERSE
  56. # endif /* VWERSE && !VWERASE */
  57.  
  58. # if defined(VDISCRD) && !defined(VDISCARD)
  59. #  define VDISCARD VDISCRD
  60. # endif /* VDISCRD && !VDISCARD */
  61.  
  62. # if defined(VFLUSHO) && !defined(VDISCARD)
  63. #  define VDISCARD VFLUSHO
  64. # endif  /* VFLUSHO && VDISCARD */
  65.  
  66. # if defined(VSTRT) && !defined(VSTART)
  67. #  define VSTART VSTRT
  68. # endif /* VSTRT && ! VSTART */
  69.  
  70. # if defined(VSTAT) && !defined(VSTATUS)
  71. #  define VSTATUS VSTAT
  72. # endif /* VSTAT && ! VSTATUS */
  73.  
  74. # ifndef ONLRET
  75. #  define ONLRET 0
  76. # endif /* ONLRET */
  77.  
  78. # ifndef TAB3
  79. #  ifdef OXTABS
  80. #   define TAB3 OXTABS
  81. #  else
  82. #   define TAB3 0
  83. #  endif /* OXTABS */
  84. # endif /* !TAB3 */
  85.  
  86. # if defined(OXTABS) && !defined(XTABS)
  87. #  define XTABS OXTABS
  88. # endif /* OXTABS && !XTABS */
  89.  
  90. # ifndef ONLCR
  91. #  define ONLCR 0
  92. # endif /* ONLCR */
  93.  
  94. # ifndef IEXTEN
  95. #  define IEXTEN 0
  96. # endif /* IEXTEN */
  97.  
  98. # ifndef ECHOCTL
  99. #  define ECHOCTL 0
  100. # endif /* ECHOCTL */
  101.  
  102. # ifndef PARENB
  103. #  define PARENB 0
  104. # endif /* PARENB */
  105.  
  106. # ifndef EXTPROC
  107. #  define EXTPROC 0
  108. # endif /* EXTPROC */
  109.  
  110. # ifndef FLUSHO
  111. #  define FLUSHO  0
  112. # endif /* FLUSHO */
  113.  
  114. # if defined(VDISABLE) && !defined(_POSIX_VDISABLE)
  115. #  define _POSIX_VDISABLE VDISABLE
  116. # endif /* VDISABLE && ! _POSIX_VDISABLE */
  117.  
  118. # ifndef _POSIX_VDISABLE
  119. #  define _POSIX_VDISABLE -1
  120. # endif /* _POSIX_VDISABLE */
  121.  
  122. /*
  123.  * Work around ISC's definition of IEXTEN which is
  124.  * XCASE!
  125.  */
  126. # ifdef ISC
  127. #  if defined(IEXTEN) && defined(XCASE)
  128. #   if IEXTEN == XCASE
  129. #    undef IEXTEN
  130. #    define IEXTEN 0
  131. #   endif /* IEXTEN == XCASE */
  132. #  endif /* IEXTEN && XCASE */
  133. # endif /* ISC */
  134.  
  135. #endif /* TERMIO || POSIX */
  136.  
  137.  
  138. /* ed.init.c -- init routines for the line editor */
  139.  
  140. int     Tty_raw_mode = 0;    /* Last tty change was to raw mode */
  141. int     MacroLvl = -1;        /* pointer to current macro nesting level; */
  142.                 /* (-1 == none) */
  143. static int Tty_quote_mode = 0;    /* Last tty change was to quote mode */
  144.  
  145. int     Tty_eight_bit = -1;    /* does the tty handle eight bits */
  146.  
  147. extern bool GotTermCaps;
  148.  
  149. #ifdef _IBMR2
  150. static bool edit_discipline = 0;
  151. union txname tx_disc;
  152. extern char strPOSIX[];
  153. #endif /* _IBMR2 */
  154.  
  155. static    int    dosetkey __P((char *, char *));
  156.  
  157. static struct tcshtty {
  158.     char *t_name;
  159.     int  t_setmask;
  160.     int  t_clrmask;
  161. } ttylist[] = {
  162.  
  163. #ifdef TERMIO
  164. # define M_INPUT    0
  165.     { "iflag:", ICRNL, (INLCR|IGNCR) },
  166. # define M_OUTPUT    1
  167.     { "oflag:", (OPOST|ONLCR), ONLRET },
  168. # define M_CONTROL    2
  169.     { "cflag:", 0, 0 },
  170. # define M_LINED    3
  171.     { "lflag:", (ISIG|ICANON|ECHO|ECHOE|ECHOCTL|IEXTEN),
  172.             (NOFLSH|ECHONL|EXTPROC|FLUSHO) },
  173.  
  174. #else /* GSTTY */
  175.  
  176. # define M_CONTROL    0
  177.     { "", (ECHO|CRMOD|ANYP), (CBREAK|RAW|LCASE|VTDELAY|ALLDELAY) },
  178. # define M_LOCAL    1
  179.     { "", (LCRTBS|LCRTERA|LCRTKIL), (LPRTERA|LFLUSHO) },
  180.  
  181. #endif /* TERMIO */
  182. };
  183.  
  184. static struct tcshmodes {
  185.     char *m_name;
  186.     int   m_value;
  187.     int   m_type;
  188. } modelist[] = {
  189. #ifdef TERMIO
  190.  
  191. # ifdef    IGNBRK
  192.     { "ignbrk",    IGNBRK,    M_INPUT },
  193. # endif /* IGNBRK */
  194. # ifdef    BRKINT
  195.     { "brkint",    BRKINT,    M_INPUT },
  196. # endif /* BRKINT */
  197. # ifdef    IGNPAR
  198.     { "ignpar",    IGNPAR,    M_INPUT },
  199. # endif /* IGNPAR */
  200. # ifdef    PARMRK
  201.     { "parmrk",    PARMRK,    M_INPUT },
  202. # endif /* PARMRK */
  203. # ifdef    INPCK
  204.     { "inpck",    INPCK,    M_INPUT },
  205. # endif /* INPCK */
  206. # ifdef    ISTRIP
  207.     { "istrip",    ISTRIP,    M_INPUT },
  208. # endif /* ISTRIP */
  209. # ifdef    INLCR
  210.     { "inlcr",    INLCR,    M_INPUT },
  211. # endif /* INLCR */
  212. # ifdef    IGNCR
  213.     { "igncr",    IGNCR,    M_INPUT },
  214. # endif /* IGNCR */
  215. # ifdef    ICRNL
  216.     { "icrnl",    ICRNL,    M_INPUT },
  217. # endif /* ICRNL */
  218. # ifdef    IUCLC
  219.     { "iuclc",    IUCLC,    M_INPUT },
  220. # endif /* IUCLC */
  221. # ifdef    IXON
  222.     { "ixon",    IXON,    M_INPUT },
  223. # endif /* IXON */
  224. # ifdef    IXANY
  225.     { "ixany",    IXANY,    M_INPUT },
  226. # endif /* IXANY */
  227. # ifdef    IXOFF
  228.     { "ixoff",    IXOFF,    M_INPUT },
  229. # endif /* IXOFF */
  230. # ifdef  IMAXBEL
  231.     { "imaxbel",IMAXBEL,M_INPUT },
  232. # endif /* IMAXBEL */
  233.  
  234. # ifdef    OPOST
  235.     { "opost",    OPOST,    M_OUTPUT },
  236. # endif /* OPOST */
  237. # ifdef    OLCUC
  238.     { "olcuc",    OLCUC,    M_OUTPUT },
  239. # endif /* OLCUC */
  240. # ifdef    ONLCR
  241.     { "onlcr",    ONLCR,    M_OUTPUT },
  242. # endif /* ONLCR */
  243. # ifdef    OCRNL
  244.     { "ocrnl",    OCRNL,    M_OUTPUT },
  245. # endif /* OCRNL */
  246. # ifdef    ONOCR
  247.     { "onocr",    ONOCR,    M_OUTPUT },
  248. # endif /* ONOCR */
  249. # ifdef ONOEOT
  250.     { "onoeot",    ONOEOT,    M_OUTPUT },
  251. # endif /* ONOEOT */
  252. # ifdef    ONLRET
  253.     { "onlret",    ONLRET,    M_OUTPUT },
  254. # endif /* ONLRET */
  255. # ifdef    OFILL
  256.     { "ofill",    OFILL,    M_OUTPUT },
  257. # endif /* OFILL */
  258. # ifdef    OFDEL
  259.     { "ofdel",    OFDEL,    M_OUTPUT },
  260. # endif /* OFDEL */
  261. # ifdef    NLDLY
  262.     { "nldly",    NLDLY,    M_OUTPUT },
  263. # endif /* NLDLY */
  264. # ifdef    CRDLY
  265.     { "crdly",    CRDLY,    M_OUTPUT },
  266. # endif /* CRDLY */
  267. # ifdef    TABDLY
  268.     { "tabdly",    TABDLY,    M_OUTPUT },
  269. # endif /* TABDLY */
  270. # ifdef    XTABS
  271.     { "xtabs",    XTABS,    M_OUTPUT },
  272. # endif /* XTABS */
  273. # ifdef    BSDLY
  274.     { "bsdly",    BSDLY,    M_OUTPUT },
  275. # endif /* BSDLY */
  276. # ifdef    VTDLY
  277.     { "vtdly",    VTDLY,    M_OUTPUT },
  278. # endif /* VTDLY */
  279. # ifdef    FFDLY
  280.     { "ffdly",    FFDLY,    M_OUTPUT },
  281. # endif /* FFDLY */
  282. # ifdef    PAGEOUT
  283.     { "pageout",PAGEOUT,M_OUTPUT },
  284. # endif /* PAGEOUT */
  285. # ifdef    WRAP
  286.     { "wrap",    WRAP,    M_OUTPUT },
  287. # endif /* WRAP */
  288.  
  289. # ifdef    CIGNORE
  290.     { "cignore",CIGNORE,M_CONTROL },
  291. # endif /* CBAUD */
  292. # ifdef    CBAUD
  293.     { "cbaud",    CBAUD,    M_CONTROL },
  294. # endif /* CBAUD */
  295. # ifdef    CSTOPB
  296.     { "cstopb",    CSTOPB,    M_CONTROL },
  297. # endif /* CSTOPB */
  298. # ifdef    CREAD
  299.     { "cread",    CREAD,    M_CONTROL },
  300. # endif /* CREAD */
  301. # ifdef    PARENB
  302.     { "parenb",    PARENB,    M_CONTROL },
  303. # endif /* PARENB */
  304. # ifdef    PARODD
  305.     { "parodd",    PARODD,    M_CONTROL },
  306. # endif /* PARODD */
  307. # ifdef    HUPCL
  308.     { "hupcl",    HUPCL,    M_CONTROL },
  309. # endif /* HUPCL */
  310. # ifdef    CLOCAL
  311.     { "clocal",    CLOCAL,    M_CONTROL },
  312. # endif /* CLOCAL */
  313. # ifdef    LOBLK
  314.     { "loblk",    LOBLK,    M_CONTROL },
  315. # endif /* LOBLK */
  316. # ifdef    CIBAUD
  317.     { "cibaud",    CIBAUD,    M_CONTROL },
  318. # endif /* CIBAUD */
  319. # ifdef CRTSCTS
  320. #  ifdef CCTS_OFLOW
  321.     { "ccts_oflow",CCTS_OFLOW,M_CONTROL },
  322. #  else
  323.     { "crtscts",CRTSCTS,M_CONTROL },
  324. #  endif /* CCTS_OFLOW */
  325. # endif /* CRTSCTS */
  326. # ifdef CRTS_IFLOW
  327.     { "crts_iflow",CRTS_IFLOW,M_CONTROL },
  328. # endif /* CRTS_IFLOW */
  329. # ifdef MDMBUF
  330.     { "mdmbuf",    MDMBUF,    M_CONTROL },
  331. # endif /* MDMBUF */
  332.  
  333. # ifdef    ISIG
  334.     { "isig",    ISIG,    M_LINED },
  335. # endif /* ISIG */
  336. # ifdef    ICANON
  337.     { "icanon",    ICANON,    M_LINED },
  338. # endif /* ICANON */
  339. # ifdef    XCASE
  340.     { "xcase",    XCASE,    M_LINED },
  341. # endif /* XCASE */
  342. # ifdef    ECHO
  343.     { "echo",    ECHO,    M_LINED },
  344. # endif /* ECHO */
  345. # ifdef    ECHOE
  346.     { "echoe",    ECHOE,    M_LINED },
  347. # endif /* ECHOE */
  348. # ifdef    ECHOK
  349.     { "echok",    ECHOK,    M_LINED },
  350. # endif /* ECHOK */
  351. # ifdef    ECHONL
  352.     { "echonl",    ECHONL,    M_LINED },
  353. # endif /* ECHONL */
  354. # ifdef    NOFLSH
  355.     { "noflsh",    NOFLSH,    M_LINED },
  356. # endif /* NOFLSH */
  357. # ifdef    TOSTOP
  358.     { "tostop",    TOSTOP,    M_LINED },
  359. # endif /* TOSTOP */
  360. # ifdef    ECHOCTL
  361.     { "echoctl",ECHOCTL,M_LINED },
  362. # endif /* ECHOCTL */
  363. # ifdef    ECHOPRT
  364.     { "echoprt",ECHOPRT,M_LINED },
  365. # endif /* ECHOPRT */
  366. # ifdef    ECHOKE
  367.     { "echoke",    ECHOKE,    M_LINED },
  368. # endif /* ECHOKE */
  369. # ifdef    DEFECHO
  370.     { "defecho",DEFECHO,M_LINED },
  371. # endif /* DEFECHO */
  372. # ifdef    FLUSHO
  373.     { "flusho",    FLUSHO,    M_LINED },
  374. # endif /* FLUSHO */
  375. # ifdef    PENDIN
  376.     { "pendin",    PENDIN,    M_LINED },
  377. # endif /* PENDIN */
  378. # ifdef    IEXTEN
  379.     { "iexten",    IEXTEN,    M_LINED },
  380. # endif /* IEXTEN */
  381. # ifdef    NOKERNINFO
  382.     { "nokerninfo",NOKERNINFO,M_LINED },
  383. # endif /* NOKERNINFO */
  384. # ifdef    ALTWERASE
  385.     { "altwerase",ALTWERASE,M_LINED },
  386. # endif /* ALTWERASE */
  387.  
  388. #else /* GSTTY */
  389.  
  390. # ifdef    TANDEM
  391.     { "tandem",    TANDEM,    M_CONTROL },
  392. # endif /* TANDEM */
  393. # ifdef    CBREAK
  394.     { "cbreak",    CBREAK,    M_CONTROL },
  395. # endif /* CBREAK */
  396. # ifdef    LCASE
  397.     { "lcase",    LCASE,    M_CONTROL },
  398. # endif /* LCASE */
  399. # ifdef    ECHO
  400.     { "echo",    ECHO,    M_CONTROL },
  401. # endif /* ECHO */    
  402. # ifdef    CRMOD
  403.     { "crmod",    CRMOD,    M_CONTROL },
  404. # endif /* CRMOD */
  405. # ifdef    RAW
  406.     { "raw",    RAW,    M_CONTROL },
  407. # endif /* RAW */
  408. # ifdef    ODDP
  409.     { "oddp",    ODDP,    M_CONTROL },
  410. # endif /* ODDP */
  411. # ifdef    EVENP
  412.     { "evenp",    EVENP,    M_CONTROL },
  413. # endif /* EVENP */
  414. # ifdef    ANYP
  415.     { "anyp",    ANYP,    M_CONTROL },
  416. # endif /* ANYP */
  417. # ifdef    NLDELAY
  418.     { "nldelay",NLDELAY,M_CONTROL },
  419. # endif /* NLDELAY */
  420. # ifdef    TBDELAY
  421.     { "tbdelay",TBDELAY,M_CONTROL },
  422. # endif /* TBDELAY */
  423. # ifdef    XTABS
  424.     { "xtabs",    XTABS,    M_CONTROL },
  425. # endif /* XTABS */
  426. # ifdef    CRDELAY
  427.     { "crdelay",CRDELAY,M_CONTROL },
  428. # endif /* CRDELAY */
  429. # ifdef    VTDELAY
  430.     { "vtdelay",VTDELAY,M_CONTROL },
  431. # endif /* VTDELAY */
  432. # ifdef    BSDELAY
  433.     { "bsdelay",BSDELAY,M_CONTROL },
  434. # endif /* BSDELAY */
  435. # ifdef    CRTBS
  436.     { "crtbs",    CRTBS,    M_CONTROL },
  437. # endif /* CRTBS */
  438. # ifdef    PRTERA
  439.     { "prtera",    PRTERA,    M_CONTROL },
  440. # endif /* PRTERA */
  441. # ifdef    CRTERA
  442.     { "crtera",    CRTERA,    M_CONTROL },
  443. # endif /* CRTERA */
  444. # ifdef    TILDE
  445.     { "tilde",    TILDE,    M_CONTROL },
  446. # endif /* TILDE */
  447. # ifdef    MDMBUF
  448.     { "mdmbuf",    MDMBUF,    M_CONTROL },
  449. # endif /* MDMBUF */
  450. # ifdef    LITOUT
  451.     { "litout",    LITOUT,    M_CONTROL },
  452. # endif /* LITOUT */
  453. # ifdef    TOSTOP
  454.     { "tostop",    TOSTOP,    M_CONTROL },
  455. # endif /* TOSTOP */
  456. # ifdef    FLUSHO
  457.     { "flusho",    FLUSHO,    M_CONTROL },
  458. # endif /* FLUSHO */
  459. # ifdef    NOHANG
  460.     { "nohang",    NOHANG,    M_CONTROL },
  461. # endif /* NOHANG */
  462. # ifdef    L001000
  463.     { "l001000",L001000,M_CONTROL },
  464. # endif /* L001000 */
  465. # ifdef    CRTKIL
  466.     { "crtkil",    CRTKIL,    M_CONTROL },
  467. # endif /* CRTKIL */
  468. # ifdef    PASS8
  469.     { "pass8",    PASS8,    M_CONTROL },
  470. # endif /* PASS8 */
  471. # ifdef    CTLECH
  472.     { "ctlech",    CTLECH,    M_CONTROL },
  473. # endif /* CTLECH */
  474. # ifdef    PENDIN
  475.     { "pendin",    PENDIN,    M_CONTROL },
  476. # endif /* PENDIN */
  477. # ifdef    DECCTQ
  478.     { "decctq",    DECCTQ,    M_CONTROL },
  479. # endif /* DECCTQ */
  480. # ifdef    NOFLSH
  481.     { "noflsh",    NOFLSH,    M_CONTROL },
  482. # endif /* NOFLSH */
  483.  
  484. # ifdef    LCRTBS
  485.     { "lcrtbs",    LCRTBS,    M_LOCAL },
  486. # endif /* LCRTBS */
  487. # ifdef    LPRTERA
  488.     { "lprtera",LPRTERA,M_LOCAL },
  489. # endif /* LPRTERA */
  490. # ifdef    LCRTERA
  491.     { "lcrtera",LCRTERA,M_LOCAL },
  492. # endif /* LCRTERA */
  493. # ifdef    LTILDE
  494.     { "ltilde",    LTILDE,    M_LOCAL },
  495. # endif /* LTILDE */
  496. # ifdef    LMDMBUF
  497.     { "lmdmbuf",LMDMBUF,M_LOCAL },
  498. # endif /* LMDMBUF */
  499. # ifdef    LLITOUT
  500.     { "llitout",LLITOUT,M_LOCAL },
  501. # endif /* LLITOUT */
  502. # ifdef    LTOSTOP
  503.     { "ltostop",LTOSTOP,M_LOCAL },
  504. # endif /* LTOSTOP */
  505. # ifdef    LFLUSHO
  506.     { "lflusho",LFLUSHO,M_LOCAL },
  507. # endif /* LFLUSHO */
  508. # ifdef    LNOHANG
  509.     { "lnohang",LNOHANG,M_LOCAL },
  510. # endif /* LNOHANG */
  511. # ifdef    LCRTKIL
  512.     { "lcrtkil",LCRTKIL,M_LOCAL },
  513. # endif /* LCRTKIL */
  514. # ifdef    LPASS8
  515.     { "lpass8",    LPASS8,    M_LOCAL },
  516. # endif /* LPASS8 */    
  517. # ifdef    LCTLECH
  518.     { "lctlech",LCTLECH,M_LOCAL },
  519. # endif /* LCTLECH */
  520. # ifdef    LPENDIN
  521.     { "lpendin",LPENDIN,M_LOCAL },
  522. # endif /* LPENDIN */
  523. # ifdef    LDECCTQ
  524.     { "ldecctq",LDECCTQ,M_LOCAL },
  525. # endif /* LDECCTQ */
  526. # ifdef    LNOFLSH
  527.     { "lnoflsh",LNOFLSH,M_LOCAL },
  528. # endif /* LNOFLSH */
  529.  
  530. #endif /* TERMIO */
  531.     { NULL, 0, -1 },
  532. };
  533.  
  534.  
  535. void
  536. dosetty(v, t)
  537.     Char **v;
  538.     struct command *t;
  539. {
  540.     struct tcshmodes *m;
  541.     char x, *d;
  542.     int aflag = 0;
  543.     Char *s;
  544.  
  545.     setname(short2str(*v++));
  546.  
  547.     if (v && *v && v[0][0] == '-' && v[0][1] == 'a' && v[0][2] == '\0') {
  548.     aflag = 1;
  549.     v++;
  550.     }
  551.     if (!v || !*v) {
  552.     int i = -1;
  553.     int len = 0, st = 0, cu;
  554.     for (m = modelist; m->m_name; m++) {
  555.         if (m->m_type != i) {
  556.         xprintf("%s%s", i != -1 ? "\n" : "", 
  557.             ttylist[m->m_type].t_name);
  558.         i = m->m_type;
  559.         st = len = strlen(ttylist[m->m_type].t_name);
  560.         }
  561.  
  562.         x = (ttylist[i].t_setmask & m->m_value) ? '+' : '\0';
  563.         x = (ttylist[i].t_clrmask & m->m_value) ? '-' : x;
  564.  
  565.         if (x != '\0' || aflag) {
  566.         cu = strlen(m->m_name) + (x != '\0') + 1;
  567.         if (len + cu >= T_Cols) {
  568.             xprintf("\n%*s", st, "");
  569.             len = st + cu;
  570.         }
  571.         else 
  572.             len += cu;
  573.         if (x != '\0')
  574.             xprintf("%c%s ", x, m->m_name);
  575.         else
  576.             xprintf("%s ", m->m_name);
  577.         }
  578.     }
  579.     xprintf("\n");
  580.     return;
  581.     }
  582.     while (v && (s = *v++)) {
  583.     switch (*s) {
  584.     case '+':
  585.     case '-':
  586.         x = *s++;
  587.         break;
  588.     default:
  589.         x = '\0';
  590.         break;
  591.     }
  592.     d = short2str(s);
  593.     for (m = modelist; m->m_name; m++)
  594.         if (strcmp(m->m_name, d) == 0)
  595.         break;
  596.     if (!m->m_name) 
  597.         stderror(ERR_NAME | ERR_SYSTEM, d, "Invalid argument");
  598.  
  599.     switch (x) {
  600.     case '+':
  601.         ttylist[m->m_type].t_setmask |= m->m_value;
  602.         ttylist[m->m_type].t_clrmask &= ~m->m_value;
  603.         break;
  604.     case '-':
  605.         ttylist[m->m_type].t_setmask &= ~m->m_value;
  606.         ttylist[m->m_type].t_clrmask |= m->m_value;
  607.         break;
  608.     default:
  609.         ttylist[m->m_type].t_setmask &= ~m->m_value;
  610.         ttylist[m->m_type].t_clrmask &= ~m->m_value;
  611.         break;
  612.     }
  613.     }
  614. } /* end dosetty */
  615.  
  616.  
  617. #ifdef SIG_WINDOW
  618. void
  619. check_window_size(force)
  620.     int     force;
  621. {
  622. #ifdef BSDSIGS
  623.     sigmask_t omask;
  624. #endif /* BSDSIGS */
  625.     int     lins, cols;
  626.  
  627.     /* don't want to confuse things here */
  628. #ifdef BSDSIGS
  629.     omask = sigblock(sigmask(SIG_WINDOW)) & ~sigmask(SIG_WINDOW);
  630. #else                /* BSDSIGS */
  631.     (void) sighold(SIG_WINDOW);
  632. #endif /* BSDSIGS */
  633.  
  634.     /*
  635.      * From: bret@shark.agps.lanl.gov (Bret Thaeler) Avoid sunview bug, where a
  636.      * partially hidden window gets a SIG_WINDOW every time the text is
  637.      * scrolled
  638.      */
  639.     if (GetSize(&lins, &cols) || force) {
  640.     if (GettingInput) {
  641.         ClearLines();
  642.         ClearDisp();
  643.         MoveToLine(0);
  644.         MoveToChar(0);
  645.         ChangeSize(lins, cols);
  646.         Refresh();
  647.     }
  648.     else
  649.         ChangeSize(lins, cols);
  650.     }
  651.  
  652. #ifdef BSDSIGS
  653.     (void) sigsetmask(omask);    /* can change it again */
  654. #else                /* BSDSIGS */
  655.     (void) sigrelse(SIG_WINDOW);
  656. #endif /* BSDSIGS */
  657. }
  658.  
  659. sigret_t
  660. /*ARGSUSED*/
  661. window_change(snum)
  662. int snum;
  663. {
  664. #if (SVID > 0) && (SVID < 3)
  665.     /* If we were called as a signal handler, restore it. */
  666.     if (snum > 0)
  667.       sigset(snum, window_change);
  668. #endif /* SVID > 0 && SVID < 3 */
  669.     check_window_size(0);
  670. #ifndef SIGVOID
  671.     return (snum);
  672. #endif 
  673. }
  674.  
  675. #endif /* SIG_WINDOW */
  676.  
  677. /* LPASS8 is new in 4.3, and makes cbreak mode provide all 8 bits.  */
  678. #ifndef LPASS8
  679. # define LPASS8 0        /* we don't have it.  Too bad!! */
  680. #endif 
  681.  
  682. #ifndef CTRL
  683. # define    CTRL(c)    ('c'&037)
  684. #endif 
  685.  
  686. void
  687. ed_set_tty_eight_bit()
  688. {
  689. #ifndef POSIX
  690. # ifdef TERMIO
  691.     struct termio ttynio;
  692. # else                /* GSTTY */
  693.     int     ttynlb;
  694. # endif /* TERMIO */
  695. #else                /* POSIX */
  696.     struct termios ttynio;
  697. #endif /* POSIX */
  698.  
  699. #ifndef POSIX
  700. # ifdef TERMIO
  701.     (void) ioctl(SHIN, TCGETA, (ioctl_t) & ttynio);
  702. # else                /* GSTTY */
  703.     (void) ioctl(SHIN, TIOCLGET, (ioctl_t) & ttynlb);
  704. # endif /* TERMIO */
  705. #else                /* POSIX */
  706.     (void) tcgetattr(SHIN, &ttynio);
  707. #endif /* POSIX */
  708.  
  709. #if defined(TERMIO) || defined(POSIX)
  710.     Tty_eight_bit = (ttynio.c_cflag & CSIZE) == CS8;
  711. #else                /* GSTTY */
  712.     Tty_eight_bit = ttynlb & (LPASS8 | LLITOUT);
  713. #endif 
  714. }
  715.  
  716. void
  717. ed_Init()
  718. {
  719.     static int havesetup = 0;
  720.  
  721.     ResetInLine();        /* reset the input pointers */
  722.     GettingInput = 0;        /* just in case */
  723.     LastKill = KillBuf;        /* no kill buffer */
  724.  
  725. #ifdef DEBUG_EDIT
  726.     CheckMaps();        /* do a little error checking on key maps */
  727. #endif 
  728.  
  729.     if (!havesetup) {        /* if we have never been called */
  730.     replacemode = 0;    /* start out in insert mode */
  731.     ed_InitMaps();
  732.     Hist_num = 0;
  733.     Expand = 0;
  734.  
  735. #ifndef POSIX
  736. # ifdef TERMIO
  737.     (void) ioctl(SHIN, TCGETA, (ioctl_t) & nio);
  738. #  ifdef CBAUD
  739.     T_Speed = nio.c_cflag & CBAUD;
  740. #  else
  741.     T_Speed = 0;
  742. #  endif 
  743. # else                /* GSTTY */
  744.     (void) ioctl(SHIN, TIOCGETP, (ioctl_t) & nb);    /* normal setup */
  745.     xb = nb;        /* new setup */
  746.     (void) ioctl(SHIN, TIOCGETC, (ioctl_t) & ntc);
  747.     xtc = ntc;
  748.     (void) ioctl(SHIN, TIOCGLTC, (ioctl_t) & nlc);
  749.     xlc = nlc;
  750. #  ifdef TIOCGPAGE
  751.     (void) ioctl(SHIN, TIOCGPAGE, (ioctl_t) & npc);
  752.     xpc = npc;
  753. #  endif /* TIOCGPAGE */
  754.     (void) ioctl(SHIN, TIOCLGET, (ioctl_t) & nlb);
  755.     xlb = nlb;
  756.     T_Speed = nb.sg_ispeed;
  757. # endif /* TERMIO */
  758. #else                /* POSIX */
  759.     (void) tcgetattr(SHIN, &nio);
  760.     T_Speed = cfgetispeed(&nio);
  761. #endif /* POSIX */
  762.  
  763. #if defined(TERMIO) || defined(POSIX)
  764.     xio = nio;
  765.  
  766.     if ((nio.c_oflag & TAB3) == TAB3) {    /* then no tabs */
  767.         T_Tabs = 0;
  768.     }
  769.     else {
  770.         T_Tabs = 1;
  771.     }
  772.  
  773. #ifdef notdef
  774.     nio.c_iflag &= ~(INLCR | IGNCR);
  775.     nio.c_iflag |= (ICRNL);
  776.  
  777.     nio.c_oflag &= ~(ONLRET);
  778.     nio.c_oflag |= (OPOST | ONLCR);
  779.     /* don't muck with c_cflag */
  780.     nio.c_lflag &= ~(NOFLSH | ECHOK | ECHONL | EXTPROC | FLUSHO);
  781.     nio.c_lflag |= (ISIG | ICANON | ECHO | ECHOE | ECHOCTL | IEXTEN);
  782. #endif 
  783.     nio.c_iflag &= ~ttylist[M_INPUT].t_clrmask;
  784.     nio.c_iflag |=  ttylist[M_INPUT].t_setmask;
  785.  
  786.     nio.c_oflag &= ~ttylist[M_OUTPUT].t_clrmask;
  787.     nio.c_oflag |=  ttylist[M_OUTPUT].t_setmask;
  788.  
  789.     nio.c_cflag &= ~ttylist[M_CONTROL].t_clrmask;
  790.     nio.c_cflag |=  ttylist[M_CONTROL].t_setmask;
  791.  
  792.     nio.c_lflag &= ~ttylist[M_LINED].t_clrmask;
  793.     nio.c_lflag |=  ttylist[M_LINED].t_setmask;
  794.  
  795. # ifdef IRIX3_3
  796.     nio.c_line = NTTYDISC;
  797. # endif /* IRIX3_3 */
  798.     nio.c_cc[VINTR] = '\003';    /* ^C */
  799.     nio.c_cc[VQUIT] = '\034';    /* ^\ */
  800.     nio.c_cc[VERASE] = '\177';    /* ^? */
  801.     nio.c_cc[VKILL] = '\025';    /* ^U */
  802.     nio.c_cc[VEOF] = '\004';/* ^D */
  803.     nio.c_cc[VEOL] = _POSIX_VDISABLE;
  804. # ifdef VEOL2
  805.     nio.c_cc[VEOL2] = _POSIX_VDISABLE;
  806. # endif 
  807. # ifdef VSWTCH
  808.     nio.c_cc[VSWTCH] = _POSIX_VDISABLE;
  809. # endif /* VSWTCH */
  810. # ifdef VERASE2
  811.     nio.c_cc[VERASE2] = _POSIX_VDISABLE;
  812. # endif /* VERASE2 */
  813. # ifdef VSTART
  814.     nio.c_cc[VSTART] = '\021';    /* ^Q */
  815. # endif /* VSTART */
  816. # ifdef VSTOP
  817.     nio.c_cc[VSTOP] = '\023';    /* ^S */
  818. # endif /* VSTOP */
  819. # ifdef VWERASE
  820.     nio.c_cc[VWERASE] = '\027';    /* ^W */
  821. # endif /* VWERASE */
  822. # ifdef VSUSP
  823.     nio.c_cc[VSUSP] = CSUSP;
  824. # endif 
  825. # ifdef VDSUSP
  826.     nio.c_cc[VDSUSP] = '\031';    /* ^Y */
  827. # endif /* VDSUSP */
  828. # ifdef VREPRINT
  829.     nio.c_cc[VREPRINT] = '\022';    /* ^R */
  830. # endif /* WREPRINT */
  831. # ifdef VDISCARD
  832.     nio.c_cc[VDISCARD] = '\017';    /* ^O */
  833. # endif /* VDISCARD */
  834. # ifdef VLNEXT
  835.     nio.c_cc[VLNEXT] = '\026';    /* ^V */
  836. # endif /* VLNEXT */
  837. # ifdef VSTATUS
  838.     nio.c_cc[VSTATUS] = '\024';    /* ^T */
  839. # endif /* VSTATUS */
  840. # ifdef VPGOFF
  841.     nio.c_cc[VPGOFF] = ' ';    /* " " */
  842. # endif /* VPGOFF */
  843. # ifdef VPAGE
  844.     nio.c_cc[VPAGE] = '\015';    /* ^M */
  845. # endif /* VPAGE */
  846.  
  847. # if (defined(OREO) || defined(hpux) || defined(_IBMR2)) && !defined(hp9000s500)
  848.  
  849.     (void) ioctl(SHIN, TIOCGLTC, (ioctl_t) & nlc);
  850.     xlc = nlc;
  851. #  ifdef VSUSP
  852.     nlc.t_suspc = nio.c_cc[VSUSP];    /* stop process signal     */
  853. #  else
  854.     nlc.t_suspc = '\032';    /* stop process signal     */
  855. #  endif 
  856.     nlc.t_dsuspc = '\031';    /* delayed stop process signal */
  857. #  ifdef hpux
  858.     /*
  859.      * These must be 0377. (Reserved)
  860.      */
  861.     nlc.t_rprntc = _POSIX_VDISABLE;    /* reprint line */
  862.     nlc.t_flushc = _POSIX_VDISABLE;    /* flush output (toggles) */
  863.     nlc.t_werasc = _POSIX_VDISABLE;    /* word erase */
  864.     nlc.t_lnextc = _POSIX_VDISABLE;    /* literal next character */
  865. #  else
  866.     nlc.t_rprntc = '\022';    /* reprint line */
  867.     nlc.t_flushc = '\017';    /* flush output (toggles) */
  868.     nlc.t_werasc = '\027';    /* word erase */
  869.     nlc.t_lnextc = '\026';    /* literal next character */
  870. #  endif /* hpux */
  871. # endif /* OREO || hpux || _IBMR2 */
  872. # ifdef SIG_WINDOW
  873.     (void) sigset(SIG_WINDOW, window_change);    /* for window systems */
  874. # endif 
  875. #else    /* GSTTY */        /* V7, Berkeley style tty */
  876.  
  877.  
  878.     if ((xb.sg_flags & XTABS) == XTABS) {    /* check for no tabs mode */
  879.         T_Tabs = 0;
  880.     }
  881.     else {
  882.         T_Tabs = 1;
  883.     }
  884.  
  885.     if (T_Tabs) {        /* order of &= and |= is important to XTABS */
  886. #ifdef notdef
  887.         nb.sg_flags &= ~(CBREAK | RAW | LCASE | XTABS | VTDELAY | ALLDELAY);
  888.         nb.sg_flags |= (ECHO | CRMOD | ANYP);
  889. #endif 
  890.         nb.sg_flags &= ~(ttylist[M_CONTROL].t_clrmask | XTABS);
  891.         nb.sg_flags |=  ttylist[M_CONTROL].t_setmask;
  892.     }
  893.     else {
  894. #ifdef notdef
  895.         nb.sg_flags &= ~(CBREAK | RAW | LCASE | VTDELAY | ALLDELAY);
  896.         nb.sg_flags |= (ECHO | CRMOD | XTABS | ANYP);
  897. #endif 
  898.         nb.sg_flags &= ~ttylist[M_CONTROL].t_clrmask;
  899.         nb.sg_flags |=  (ttylist[M_CONTROL].t_setmask | XTABS);
  900.     }
  901. #ifdef notdef
  902.     nlb &= ~(LPRTERA);    /* let 8-bit mode stand as set */
  903.     nlb |= (LCRTBS | LCRTERA | LCRTKIL);
  904. #endif 
  905.     nlb &= ~ttylist[M_LOCAL].t_clrmask;
  906.     nlb |=  ttylist[M_LOCAL].t_setmask;
  907.  
  908.     nb.sg_erase = '\177';    /* del prev. char == DEL */
  909.     nb.sg_kill = '\025';    /* special case of del region */
  910.  
  911.     ntc.t_intrc = '\003';    /* SIGINTR */
  912.     ntc.t_quitc = '\034';    /* SIGQUIT */
  913.     ntc.t_startc = '\021';    /* start output */
  914.     ntc.t_stopc = '\023';    /* stop output     */
  915.     ntc.t_eofc = '\004';    /* no eof char during input... */
  916. # ifdef masscomp
  917.     /* NUL is prefered to <undef> in this char, DAS DEC-90. */
  918.     ntc.t_brkc = '\0';    /* input delimiter (like nl) */
  919. # else
  920.     ntc.t_brkc = -1;    /* input delimiter (like nl) */
  921. # endif 
  922.  
  923.     nlc.t_suspc = '\032';    /* stop process signal     */
  924.     nlc.t_dsuspc = '\031';    /* delayed stop process signal     */
  925.     nlc.t_rprntc = '\022';    /* reprint line */
  926.     nlc.t_flushc = '\017';    /* flush output (toggles) */
  927.     nlc.t_werasc = '\027';    /* word erase */
  928.     nlc.t_lnextc = '\026';    /* literal next character */
  929.  
  930. # ifdef TIOCGPAGE
  931.     npc.tps_length = 0;
  932.     npc.tps_lpos = 0;
  933.     npc.tps_statc = '\024';    /* Show status ^T */
  934.     npc.tps_pagec = '\040';    /* show next page " " */
  935.     npc.tps_pgoffc = '\015';/* Ignore paging until input ^M */
  936.     npc.tps_flag = 0;
  937. # endif /* TIOCGPAGE */
  938.  
  939. # ifdef SIG_WINDOW
  940.     (void) sigset(SIG_WINDOW, window_change);    /* for window systems */
  941. # endif 
  942. #endif /* TERMIO */
  943.     }
  944.  
  945.     /*
  946.      * if we have been called before but GotTermCaps isn't set, our TERM has
  947.      * changed, so get new termcaps and try again
  948.      */
  949.  
  950.     if (!GotTermCaps)
  951.     GetTermCaps();        /* does the obvious, but gets term type each
  952.                  * time */
  953.  
  954. #if defined(TERMIO) || defined(POSIX)
  955.     xio.c_iflag &= ~(IGNCR);
  956.     xio.c_iflag |= (INLCR | ICRNL);
  957.  
  958.     Tty_eight_bit = (xio.c_cflag & CSIZE) == CS8;
  959.  
  960.     xio.c_oflag &= ~(ONLRET);
  961.     xio.c_oflag |= (OPOST | ONLCR);
  962.  
  963.     /* don't mask out ECHOE cause programs need it */
  964.     xio.c_lflag &= ~(NOFLSH | ICANON | ECHO | ECHOK | ECHONL | 
  965.              EXTPROC | IEXTEN | FLUSHO);
  966.     xio.c_lflag |= (ISIG);
  967.  
  968. # ifdef IRIX3_3
  969.     xio.c_line = NTTYDISC;
  970. # endif /* IRIX3_3 */
  971.     xio.c_cc[VINTR] = '\003';    /* ^C */
  972.     xio.c_cc[VQUIT] = '\034';    /* ^\ */
  973.     xio.c_cc[VERASE] = '\177';    /* ^? */
  974.     xio.c_cc[VKILL] = '\025';    /* ^U */
  975.     xio.c_cc[VMIN] = 1;        /* one char at a time input */
  976.     xio.c_cc[VTIME] = 0;    /* don't time out */
  977. # ifdef VEOL2
  978.     xio.c_cc[VEOL2] = _POSIX_VDISABLE;
  979. # endif /* VEOL2 */
  980. # ifdef VSWTCH
  981.     xio.c_cc[VSWTCH] = _POSIX_VDISABLE;
  982. # endif /* VSWTCH */
  983. # ifdef VSTART
  984.     xio.c_cc[VSTART] = '\021';    /* ^Q */
  985. # endif /* VSTART */
  986. # ifdef VSTOP
  987.     xio.c_cc[VSTOP] = '\023';    /* ^S */
  988. # endif /* VSTOP */
  989. # ifdef VWERASE
  990.     xio.c_cc[VWERASE] = _POSIX_VDISABLE;
  991. # endif /* VWERASE */
  992. # ifdef VSUSP
  993.     xio.c_cc[VSUSP] = _POSIX_VDISABLE;
  994. # endif /* VSUSP */
  995. # ifdef VDSUSP
  996.     xio.c_cc[VDSUSP] = _POSIX_VDISABLE;
  997. # endif /* VDSUSP */
  998. # ifdef VREPRINT
  999.     xio.c_cc[VREPRINT] = _POSIX_VDISABLE;
  1000. # endif /* VREPRINT */
  1001. # ifdef VDISCARD
  1002.     xio.c_cc[VDISCARD] = '\017';/* ^O */
  1003. # endif /* VDISCARD */
  1004. # ifdef VLNEXT
  1005.     xio.c_cc[VLNEXT] = _POSIX_VDISABLE;
  1006. # endif /* VLNEXT */
  1007. # ifdef VSTATUS
  1008.     xio.c_cc[VSTATUS] = '\024';    /* ^T */
  1009. # endif /* VSTATUS */
  1010. # ifdef VPGOFF
  1011.     xio.c_cc[VPGOFF] = ' ';    /* " " */
  1012. # endif /* VPGOFF */
  1013. # ifdef VPAGE
  1014.     xio.c_cc[VPAGE] = '\015';    /* ^M */
  1015. # endif /* VPAGE */
  1016.  
  1017. # if (defined(OREO) || defined(hpux) || defined(_IBMR2)) && !defined(hp9000s500)
  1018. #  ifdef VSUSP
  1019.     xlc.t_suspc = xio.c_cc[VSUSP];    /* stop process signal     */
  1020. #  else
  1021.     xlc.t_suspc = _POSIX_VDISABLE;    /* stop process signal     */
  1022. #  endif 
  1023.     xlc.t_dsuspc = _POSIX_VDISABLE;    /* delayed stop process signal     */
  1024. #  ifdef hpux
  1025.     /*
  1026.      * These must be _POSIX_VDISABLE. (Reserved)
  1027.      */
  1028.     xlc.t_rprntc = _POSIX_VDISABLE;    /* reprint line */
  1029.     xlc.t_flushc = _POSIX_VDISABLE;    /* flush output (toggles) */
  1030.     xlc.t_werasc = _POSIX_VDISABLE;    /* word erase */
  1031.     xlc.t_lnextc = _POSIX_VDISABLE;    /* literal next character */
  1032. #  else
  1033.     xlc.t_rprntc = _POSIX_VDISABLE;    /* reprint line */
  1034.     xlc.t_flushc = '\017';        /* flush output */
  1035.     xlc.t_werasc = _POSIX_VDISABLE;    /* word erase */
  1036.     xlc.t_lnextc = _POSIX_VDISABLE;    /* literal next character */
  1037. #  endif /* hpux */
  1038. # endif /* OREO || hpux || _IBMR2 */
  1039. #else /* GSTTY */
  1040.     if (T_Tabs) {        /* order of &= and |= is important to XTABS */
  1041.     xb.sg_flags &= ~(RAW | ECHO | LCASE | XTABS | VTDELAY | ALLDELAY);
  1042. # ifdef __MINT__
  1043. /* TOS, and older versions of MiNT, have trouble with CBREAK mode, so we use
  1044.  * raw mode instead
  1045.  */
  1046.     if (__mint < 91)
  1047.         xb.sg_flags |= (RAW | CRMOD | ANYP);
  1048.     else
  1049. # endif /* __MINT__ */
  1050.     xb.sg_flags |= (CBREAK | CRMOD | ANYP);
  1051.     }
  1052.     else {
  1053.     xb.sg_flags &= ~(RAW | ECHO | LCASE | VTDELAY | ALLDELAY);
  1054. # ifdef __MINT__
  1055.     if (__mint < 91)
  1056.         xb.sg_flags |= (RAW | CRMOD | ANYP | XTABS);
  1057.     else
  1058. # endif /* __MINT__ */
  1059.     xb.sg_flags |= (CBREAK | CRMOD | ANYP | XTABS);
  1060.     }
  1061.  
  1062.     xb.sg_erase = '\177';    /* del prev. char == DEL */
  1063.     xb.sg_kill = '\025';    /* special case of del region */
  1064.     /* bugfix by Michael Boom */
  1065.  
  1066.     xtc.t_intrc = '\003';    /* SIGINTR */
  1067.     xtc.t_quitc = '\034';    /* SIGQUIT */
  1068.     xtc.t_startc = '\021';    /* start output */
  1069.     xtc.t_stopc = '\023';    /* stop output     */
  1070.     xtc.t_eofc = -1;        /* no eof char during input... */
  1071. # ifdef masscomp
  1072.     /* NUL is prefered to <undef> in this char, DAS DEC-90. */
  1073.     xtc.t_brkc = '\0';        /* input delimiter (like nl) */
  1074. # else
  1075.     xtc.t_brkc = -1;        /* input delimiter (like nl) */
  1076. # endif 
  1077.  
  1078.     xlc.t_suspc = -1;        /* stop process signal (was CTRL(z)) */
  1079.     xlc.t_dsuspc = -1;        /* delayed stop process signal     */
  1080.     xlc.t_rprntc = -1;        /* reprint line */
  1081.     xlc.t_flushc = '\017';    /* flush output */
  1082.     xlc.t_werasc = -1;        /* word erase */
  1083.     xlc.t_lnextc = -1;        /* literal next character */
  1084.  
  1085. # ifdef TIOCGPAGE
  1086.     xpc.tps_length = 0;
  1087.     xpc.tps_lpos = 0;
  1088.     xpc.tps_statc = -1;        /* disable show status */
  1089.     xpc.tps_pagec = -1;        /* disable show next page */
  1090.     xpc.tps_pgoffc = -1;    /* disable Ignore paging until input */
  1091.     xpc.tps_flag = 0;
  1092. # endif /* TIOCGPAGE */
  1093.  
  1094.     xlb &= ~LPRTERA;
  1095.     xlb |= (LCRTBS | LCRTERA | LCRTKIL);
  1096.     Tty_eight_bit = nlb & (LPASS8 | LLITOUT);
  1097. #endif /* TERMIO || POSIX */
  1098.     havesetup = 1;
  1099.  
  1100.     /* Make sure the tty has a well-defined initial state */
  1101.     /* But don't bother to alter the settings if we are not editing */
  1102.     if (editing) {
  1103.     Tty_raw_mode = 0;
  1104.     (void) Rawmode();
  1105.     }
  1106. }
  1107.  
  1108. static int
  1109. dosetkey(tcp, ncp)
  1110.     char   *tcp, *ncp;
  1111. {
  1112.     if ((*tcp & 0377) > 0 && (*tcp & 0377) < 0377) {
  1113.     *ncp = *tcp;
  1114.     return 1;
  1115.     }
  1116.     return 0;
  1117. }
  1118.  
  1119. /* 
  1120.  * Check and re-init the line. set the terminal into 1 char at a time mode.
  1121.  */
  1122. int
  1123. Rawmode()
  1124. {
  1125. #ifdef POSIX
  1126.     speed_t tspeed;
  1127. #endif /* POSIX */
  1128.  
  1129.     if (Tty_raw_mode)
  1130.     return (0);
  1131. #ifdef _IBMR2
  1132.     tx_disc.tx_which = 0;
  1133.     if (ioctl(FSHTTY, TXGETLD, (ioctl_t) & tx_disc) < 0)
  1134.     return (-1);
  1135.     if (strcmp(tx_disc.tx_name, strPOSIX) != 0) {
  1136.     edit_discipline = 1;
  1137.     if (ioctl(FSHTTY, TXSETLD, (ioctl_t) strPOSIX) < 0)
  1138.         return (-1);
  1139.     }
  1140. #endif /* _IBMR2 */
  1141.  
  1142. #ifndef POSIX
  1143. # ifdef TERMIO
  1144.     if (ioctl(SHIN, TCGETA, (ioctl_t) & testio) < 0)
  1145.     return (-1);        /* SHIN has been closed */
  1146. # else                /* GSTTY */
  1147.     if (ioctl(SHIN, TIOCGETP, (ioctl_t) & testsgb) < 0)
  1148.     return (-1);        /* SHIN has been closed */
  1149.     /* test the normal flags */
  1150. # endif /* TERMIO */
  1151. #else                /* POSIX */
  1152.     if (tcgetattr(SHIN, &testio) < 0)
  1153.     return (-1);        /* SHIN has been closed */
  1154. #endif /* POSIX */
  1155.  
  1156. #if defined(POSIX) || defined(TERMIO)
  1157.     Tty_eight_bit = (testio.c_cflag & CSIZE) == CS8;
  1158.     if (testio.c_cflag != nio.c_cflag) { 
  1159.     nio.c_cflag = testio.c_cflag;
  1160.     nio.c_cflag &= ~ttylist[M_CONTROL].t_clrmask;
  1161.     nio.c_cflag |=  ttylist[M_CONTROL].t_setmask;
  1162.  
  1163.     xio.c_cflag = testio.c_cflag;
  1164.     }
  1165. # ifdef POSIX
  1166.     /*
  1167.      * Fix from: Steven (Steve) B. Green <xrsbg@charney.gsfc.nasa.gov>
  1168.      * Speed was not being set up correctly under POSIX.
  1169.      */
  1170.     if ((tspeed = cfgetispeed(&testio)) == 0)
  1171.         tspeed = cfgetospeed(&testio);
  1172.     if (tspeed != cfgetispeed(&nio)) {
  1173.     T_Speed = tspeed;
  1174.     (void) cfsetispeed(&nio, T_Speed);
  1175.     (void) cfsetospeed(&nio, T_Speed);
  1176.     (void) cfsetispeed(&xio, T_Speed);
  1177.     (void) cfsetospeed(&xio, T_Speed);
  1178.     }
  1179. # else /* !POSIX */
  1180. #  ifdef CBAUD
  1181.     T_Speed = nio.c_cflag & CBAUD;
  1182. #  else
  1183.     T_Speed = 0;
  1184. #  endif /* CBAUD */
  1185. # endif /* !POSIX */
  1186.  
  1187.     if ((testio.c_lflag != nio.c_lflag) &&
  1188.     (testio.c_lflag != xio.c_lflag)) {
  1189.     nio.c_lflag = testio.c_lflag;
  1190. #ifdef notdef
  1191.     nio.c_lflag &= ~(NOFLSH | ECHOK | ECHONL | EXTPROC | FLUSHO);
  1192.     nio.c_lflag |= (ISIG | ICANON | IEXTEN | ECHO | ECHOE | ECHOCTL);
  1193. #endif 
  1194.     nio.c_lflag &= ~ttylist[M_LINED].t_clrmask;
  1195.     nio.c_lflag |=  ttylist[M_LINED].t_setmask;
  1196.  
  1197.     xio.c_lflag = testio.c_lflag;
  1198.     /* don't mask out ECHOE cause programs need it */
  1199.     xio.c_lflag &= ~(NOFLSH | ICANON | IEXTEN | ECHO | ECHOK |
  1200.              ECHONL | ECHOCTL | EXTPROC | FLUSHO);
  1201.     xio.c_lflag |= (ISIG);
  1202.     }
  1203.  
  1204.     if ((testio.c_iflag != nio.c_iflag) &&
  1205.     (testio.c_iflag != xio.c_iflag)) {
  1206.     nio.c_iflag = testio.c_iflag;
  1207. #ifdef notdef
  1208.     nio.c_iflag &= ~(INLCR | IGNCR);
  1209.     nio.c_iflag |= (ICRNL);
  1210. #endif 
  1211.     nio.c_iflag &= ~ttylist[M_INPUT].t_clrmask;
  1212.     nio.c_iflag |=  ttylist[M_INPUT].t_setmask;
  1213.  
  1214.     xio.c_iflag = testio.c_iflag;
  1215.     xio.c_iflag &= ~(INLCR | IGNCR);
  1216.     xio.c_iflag |= (ICRNL);
  1217.     }
  1218.  
  1219.     if ((testio.c_oflag != nio.c_oflag) &&
  1220.     (testio.c_oflag != xio.c_oflag)) {
  1221.     /* Christos: There was and ifdef here that would set ONLRET!?? */
  1222.     nio.c_oflag = testio.c_oflag;
  1223. #ifdef notdef
  1224.     nio.c_oflag &= ~(ONLRET);
  1225.     nio.c_oflag |= (OPOST | ONLCR);
  1226. #endif 
  1227.     nio.c_oflag &= ~ttylist[M_OUTPUT].t_clrmask;
  1228.     nio.c_oflag |=  ttylist[M_OUTPUT].t_setmask;
  1229.  
  1230.     xio.c_oflag = testio.c_oflag;
  1231.     xio.c_oflag &= ~(ONLRET);
  1232.     xio.c_oflag |= (OPOST | ONLCR);
  1233.     }
  1234.     if ((nio.c_oflag & TAB3) == TAB3) {    /* check for no tabs mode */
  1235.     T_Tabs = 0;
  1236.     }
  1237.     else {
  1238.     T_Tabs = CanWeTab();
  1239.     }
  1240.     if (dosetkey((char *) &testio.c_cc[VINTR], (char *) &nio.c_cc[VINTR]))
  1241.     (void) dosetkey((char *) &testio.c_cc[VINTR], 
  1242.             (char *) &xio.c_cc[VINTR]);
  1243.     if (dosetkey((char *) &testio.c_cc[VQUIT], (char *) &nio.c_cc[VQUIT]))
  1244.     (void) dosetkey((char *) &testio.c_cc[VQUIT], 
  1245.             (char *) &xio.c_cc[VQUIT]);
  1246.     if (dosetkey((char *) &testio.c_cc[VERASE], (char *) &nio.c_cc[VERASE]))
  1247.     (void) dosetkey((char *) &testio.c_cc[VERASE],
  1248.             (char *) &xio.c_cc[VERASE]);
  1249.     if (dosetkey((char *) &testio.c_cc[VKILL], (char *) &nio.c_cc[VKILL]))
  1250.     (void) dosetkey((char *) &testio.c_cc[VKILL], 
  1251.             (char *) &xio.c_cc[VKILL]);
  1252.     if (testio.c_cc[VEOF] != 1) {    /* 'cause VEOL == VNUM, and 1 is raw
  1253.                      * mode */
  1254.     (void) dosetkey((char *) &testio.c_cc[VEOF], (char *) &nio.c_cc[VEOF]);
  1255.     (void) dosetkey((char *) &testio.c_cc[VEOL], (char *) &nio.c_cc[VEOL]);
  1256.     }
  1257. # ifdef VSWTCH
  1258.     if (dosetkey((char *) &testio.c_cc[VSWTCH], (char *) &nio.c_cc[VSWTCH]))
  1259.     (void) dosetkey((char *) &testio.c_cc[VSWTCH],
  1260.             (char *) &xio.c_cc[VSWTCH]);
  1261. # endif /* VSWTCH */
  1262. # ifdef VEOL2
  1263.     if (dosetkey((char *) &testio.c_cc[VEOL2], (char *) &nio.c_cc[VEOL2]))
  1264.     (void) dosetkey((char *) &testio.c_cc[VEOL2], 
  1265.             (char *) &xio.c_cc[VEOL2]);
  1266. # endif /* VEOL2 */
  1267. # ifdef VSTART
  1268.     if (dosetkey((char *) &testio.c_cc[VSTART], (char *) &nio.c_cc[VSTART]))
  1269.     (void) dosetkey((char *) &testio.c_cc[VSTART],
  1270.             (char *) &xio.c_cc[VSTART]);
  1271. # endif /* VSTART */
  1272. # ifdef VSTOP
  1273.     if (dosetkey((char *) &testio.c_cc[VSTOP], (char *) &nio.c_cc[VSTOP]))
  1274.     (void) dosetkey((char *) &testio.c_cc[VSTOP], 
  1275.             (char *) &xio.c_cc[VSTOP]);
  1276. # endif /* VSTOP */
  1277. # ifdef VWERASE
  1278.     (void) dosetkey((char *) &testio.c_cc[VWERASE], 
  1279.             (char *) &nio.c_cc[VWERASE]);
  1280. # endif /* VWERASE */
  1281. # ifdef VREPRINT
  1282.     (void) dosetkey((char *) &testio.c_cc[VREPRINT],
  1283.             (char *) &nio.c_cc[VREPRINT]);
  1284. # endif /* VREPRINT */
  1285. # ifdef VSUSP
  1286.     (void) dosetkey((char *) &testio.c_cc[VSUSP], (char *) &nio.c_cc[VSUSP]);
  1287. # endif /* VSUSP */
  1288. # ifdef VDSUSP
  1289.     (void) dosetkey((char *) &testio.c_cc[VDSUSP], (char *) &nio.c_cc[VDSUSP]);
  1290. # endif /* VDSUSP */
  1291. # ifdef VLNEXT
  1292.     (void) dosetkey((char *) &testio.c_cc[VLNEXT], (char *) &nio.c_cc[VLNEXT]);
  1293. # endif /* VLNEXT */
  1294. # ifdef VDISCARD
  1295.     if (dosetkey((char *) &testio.c_cc[VDISCARD], (char *) &nio.c_cc[VDISCARD]))
  1296.     (void) dosetkey((char *) &testio.c_cc[VDISCARD],
  1297.             (char *) &xio.c_cc[VDISCARD]);
  1298. # endif /* VDISCARD */
  1299. # ifdef VSTATUS
  1300.     if (dosetkey((char *) &testio.c_cc[VSTATUS], (char *) &nio.c_cc[VSTATUS]))
  1301.     (void) dosetkey((char *) &testio.c_cc[VSTATUS],
  1302.             (char *) &xio.c_cc[VSTATUS]);
  1303. # endif /* VSTATUS */
  1304. # ifdef VPGOFF
  1305.     if (dosetkey((char *) &testio.c_cc[VPGOFF], (char *) &nio.c_cc[VPGOFF]))
  1306.     (void) dosetkey((char *) &testio.c_cc[VPGOFF],
  1307.             (char *) &xio.c_cc[VPGOFF]);
  1308. # endif /* VPGOFF */
  1309. # ifdef VPAGE
  1310.     if (dosetkey((char *) &testio.c_cc[VPAGE], (char *) &nio.c_cc[VPAGE]))
  1311.     (void) dosetkey((char *) &testio.c_cc[VPAGE],
  1312.             (char *) &xio.c_cc[VPAGE]);
  1313. # endif /* VPAGE */
  1314.  
  1315. # ifndef POSIX
  1316.     if (ioctl(SHIN, TCSETAW, (ioctl_t) & xio) < 0)
  1317.     return (-1);
  1318. # else /* POSIX */
  1319.     if (tcsetattr(SHIN, TCSADRAIN, &xio) < 0)
  1320.     return (-1);
  1321. # endif /* POSIX */
  1322.  
  1323. # if (defined(OREO) || defined(hpux) || defined(_IBMR2)) && !defined(hp9000s500)
  1324.     /* get and set the new local chars */
  1325.     if (ioctl(SHIN, TIOCGLTC, (ioctl_t) & testlc) < 0)
  1326.     return (-1);
  1327. #ifdef VSUSP
  1328.     testlc.t_suspc = nio.c_cc[VSUSP];    /* stop process signal     */
  1329. #endif 
  1330.     (void) dosetkey((char *) &testlc.t_suspc, (char *) &nlc.t_suspc);
  1331.     (void) dosetkey((char *) &testlc.t_dsuspc, (char *) &nlc.t_dsuspc);
  1332. # ifndef hpux
  1333.     (void) dosetkey((char *) &testlc.t_rprntc, (char *) &nlc.t_rprntc);
  1334.     if (dosetkey((char *) &testlc.t_flushc, (char *) &nlc.t_flushc))
  1335.     xlc.t_flushc = nlc.t_flushc;
  1336.     (void) dosetkey((char *) &testlc.t_werasc, (char *) &nlc.t_werasc);
  1337.     (void) dosetkey((char *) &testlc.t_lnextc, (char *) &nlc.t_lnextc);
  1338. # endif /* hpux */
  1339.     if (ioctl(SHIN, TIOCSLTC, (ioctl_t) & xlc) < 0)
  1340.     return (-1);
  1341. # endif /* OREO || hpux || _IBMR2 */
  1342.  
  1343. #else /* GSTTY */        /* for BSD... */
  1344.  
  1345.     if (testsgb.sg_ispeed != nb.sg_ispeed) {
  1346.     nb.sg_ispeed = testsgb.sg_ispeed;
  1347.     xb.sg_ispeed = testsgb.sg_ispeed;
  1348.     }
  1349.     if (testsgb.sg_ospeed != nb.sg_ospeed) {
  1350.     nb.sg_ospeed = testsgb.sg_ospeed;
  1351.     xb.sg_ospeed = testsgb.sg_ospeed;
  1352.     }
  1353.     T_Speed = nb.sg_ispeed;
  1354.  
  1355.     /* get and set the terminal characters */
  1356.     /* bugfix by Bruce Robertson <bruce%tigger.gwd.tek.com@relay.cs.net> */
  1357.     /* include erase and kill in the tests */
  1358.     if (dosetkey((char *) &testsgb.sg_erase, (char *) &nb.sg_erase))
  1359.     xb.sg_erase = nb.sg_erase;
  1360.     if (dosetkey((char *) &testsgb.sg_kill, (char *) &nb.sg_kill))
  1361.     xb.sg_kill = nb.sg_kill;
  1362.  
  1363.     (void) ioctl(SHIN, TIOCGETC, (ioctl_t) & testtc);
  1364.     if (dosetkey((char *) &testtc.t_intrc, (char *) &ntc.t_intrc))
  1365.     xtc.t_intrc = ntc.t_intrc;
  1366.     if (dosetkey((char *) &testtc.t_quitc, (char *) &ntc.t_quitc))
  1367.     xtc.t_quitc = ntc.t_quitc;
  1368.     if (dosetkey((char *) &testtc.t_startc, (char *) &ntc.t_startc))
  1369.     xtc.t_startc = ntc.t_startc;
  1370.     if (dosetkey((char *) &testtc.t_stopc, (char *) &ntc.t_stopc))
  1371.     xtc.t_stopc = ntc.t_stopc;
  1372.     if (dosetkey((char *) &testtc.t_eofc, (char *) &ntc.t_eofc))
  1373.     xtc.t_eofc = ntc.t_eofc;/* someone might want to change EOF */
  1374.     /* in general, t_brkc shouldn't change */
  1375.     (void) dosetkey((char *) &testtc.t_brkc, (char *) &ntc.t_brkc);
  1376.  
  1377.     if (ioctl(SHIN, TIOCLGET, (ioctl_t) & testnlb) < 0)
  1378.     return (-1);
  1379.  
  1380.     Tty_eight_bit = testnlb & (LPASS8 | LLITOUT);
  1381.  
  1382.     /* If they have changed any tty settings, we have to keep up with them. */
  1383.     /* PWP: but only believe them if changes are made to cooked mode! */
  1384.     if (((testsgb.sg_flags != nb.sg_flags) || (testnlb != nlb)) &&
  1385.     ((testsgb.sg_flags != xb.sg_flags) || (testnlb != xlb)) &&
  1386.     !(testsgb.sg_flags & (RAW | CBREAK))) {
  1387.  
  1388.     nb.sg_flags = testsgb.sg_flags;
  1389.  
  1390.     /*
  1391.      * re-test for some things here (like maybe the user typed "stty -tabs"
  1392.      */
  1393.     if ((nb.sg_flags & XTABS) == XTABS) {    /* check for no tabs mode */
  1394.         T_Tabs = 0;
  1395.     }
  1396.     else {
  1397.         T_Tabs = CanWeTab();
  1398.     }
  1399.  
  1400. #ifdef notdef
  1401.     nb.sg_flags &= ~(CBREAK | RAW | LCASE | VTDELAY | ALLDELAY);
  1402.     nb.sg_flags |= (ECHO | CRMOD | ANYP);
  1403. #endif 
  1404.     nb.sg_flags &= ~ttylist[M_CONTROL].t_clrmask;
  1405.     nb.sg_flags |=  ttylist[M_CONTROL].t_setmask;
  1406.  
  1407.     if (T_Tabs) {        /* order of &= and |= is important to XTABS */
  1408.         nb.sg_flags &= ~XTABS;
  1409.     }
  1410.     else {
  1411.         nb.sg_flags |= XTABS;
  1412.     }
  1413.  
  1414.     xb.sg_flags = testsgb.sg_flags;
  1415.     if (T_Tabs) {
  1416.         xb.sg_flags &= ~(RAW | ECHO | LCASE | XTABS | VTDELAY | ALLDELAY);
  1417.         xb.sg_flags |= (CBREAK | CRMOD | ANYP);
  1418.     }
  1419.     else {
  1420.         xb.sg_flags &= ~(RAW | ECHO | LCASE | VTDELAY | ALLDELAY);
  1421.         xb.sg_flags |= (CBREAK | CRMOD | ANYP | XTABS);
  1422.     }
  1423.  
  1424.     nlb = testnlb;
  1425. /*
  1426.  * Bugfix: turn off output flushing.  By:
  1427.  * Justin Bur
  1428.  * Universite de Montreal - IRO        uunet!utai!musocs!iros1!justin
  1429.  * Montreal (Qc) Canada H3C 3J7          <bur%iro.udem.cdn@ubc.csnet>
  1430.  * Thanks!
  1431.  */
  1432. #ifdef notdef
  1433.     nlb &= ~(LPRTERA | LFLUSHO);
  1434.     nlb |= (LCRTBS | LCRTERA | LCRTKIL);
  1435. #endif 
  1436.     nlb &= ~ttylist[M_LOCAL].t_clrmask;
  1437.     nlb |=  ttylist[M_LOCAL].t_setmask;
  1438.  
  1439.     xlb = nlb;
  1440.     }
  1441.  
  1442.     /* get and set the new local chars */
  1443.     if (ioctl(SHIN, TIOCGLTC, (ioctl_t) & testlc) < 0)
  1444.     return (-1);
  1445. # ifdef TIOCGPAGE
  1446.     if (ioctl(SHIN, TIOCGPAGE, (ioctl_t) & testpc) < 0)
  1447.     return (-1);
  1448.     (void) dosetkey((char *) &testpc.tps_statc, (char *) &npc.tps_statc);
  1449.     (void) dosetkey((char *) &testpc.tps_pagec, (char *) &npc.tps_pagec);
  1450.     (void) dosetkey((char *) &testpc.tps_pgoffc, (char *) &npc.tps_pgoffc);
  1451. # endif /* TIOCGPAGE */
  1452.  
  1453.     (void) dosetkey((char *) &testlc.t_suspc, (char *) &nlc.t_suspc);
  1454.     (void) dosetkey((char *) &testlc.t_dsuspc, (char *) &nlc.t_dsuspc);
  1455.     if (dosetkey((char *) &testlc.t_flushc, (char *) &nlc.t_flushc))
  1456.     xlc.t_flushc = nlc.t_flushc;
  1457.     (void) dosetkey((char *) &testlc.t_werasc, (char *) &nlc.t_werasc);
  1458.     (void) dosetkey((char *) &testlc.t_rprntc, (char *) &nlc.t_rprntc);
  1459.     (void) dosetkey((char *) &testlc.t_lnextc, (char *) &nlc.t_lnextc);
  1460.  
  1461.     if (ioctl(SHIN, TIOCSETN, (ioctl_t) & xb) < 0)
  1462.     return (-1);
  1463.     if (ioctl(SHIN, TIOCSETC, (ioctl_t) & xtc) < 0)
  1464.     return (-1);
  1465.     if (ioctl(SHIN, TIOCSLTC, (ioctl_t) & xlc) < 0)
  1466.     return (-1);
  1467. # ifdef TIOCGPAGE
  1468.     if (ioctl(SHIN, TIOCSPAGE, (ioctl_t) & xpc) < 0)
  1469.     return (-1);
  1470. # endif /* TIOCGPAGE */
  1471.     if (ioctl(SHIN, TIOCLSET, (ioctl_t) & xlb) < 0)
  1472.     return (-1);
  1473. # endif /* TERMIO || POSIX */
  1474.     Tty_raw_mode = 1;
  1475.     flush();            /* flush any buffered output */
  1476.     return (0);
  1477. }
  1478.  
  1479. int
  1480. Cookedmode()
  1481. {                /* set tty in normal setup */
  1482.     sigret_t(*orig_intr) ();
  1483.  
  1484. #ifdef _IBMR2
  1485.     if (edit_discipline) {
  1486.     if (ioctl(SHIN, TXSETLD, (ioctl_t) & tx_disc) < 0)
  1487.         return (-1);
  1488.     edit_discipline = 0;
  1489.     }
  1490. #endif /* _IBMR2 */
  1491.     if (!Tty_raw_mode)
  1492.     return (0);
  1493.  
  1494. #ifdef BSDSIGS
  1495.     orig_intr = signal(SIGINT, SIG_IGN);    /* hold this for reseting tty */
  1496. #else
  1497.     orig_intr = sigset(SIGINT, SIG_IGN);    /* hold this for reseting tty */
  1498. #endif /* BSDSIGS */
  1499. #ifndef POSIX
  1500. # ifdef TERMIO
  1501.     if (ioctl(SHIN, TCSETAW, (ioctl_t) & nio) < 0)
  1502.     return (-1);
  1503. # if (defined(OREO) || defined(hpux) || defined(_IBMR2)) && !defined(hp9000s500)
  1504.     if (ioctl(SHIN, TIOCSLTC, (ioctl_t) & nlc) < 0)
  1505.     return (-1);
  1506. #  endif /* OREO || hpux || _IBMR2 */
  1507. # else    /* GSTTY */        /* for BSD... */
  1508.     if (ioctl(SHIN, TIOCSETN, (ioctl_t) & nb) < 0)
  1509.     return (-1);
  1510.     if (ioctl(SHIN, TIOCSETC, (ioctl_t) & ntc) < 0)
  1511.     return (-1);
  1512.     if (ioctl(SHIN, TIOCSLTC, (ioctl_t) & nlc) < 0)
  1513.     return (-1);
  1514. # ifdef TIOCGPAGE
  1515.     if (ioctl(SHIN, TIOCSPAGE, (ioctl_t) & npc) < 0)
  1516.     return (-1);
  1517. # endif /* TIOCGPAGE */
  1518.     if (ioctl(SHIN, TIOCLSET, (ioctl_t) & nlb) < 0)
  1519.     return (-1);
  1520. # endif /* TERMIO */
  1521. #else                /* POSIX */
  1522.     if (tcsetattr(SHIN, TCSADRAIN, &nio) < 0)
  1523.     return (-1);
  1524. # if defined(OREO) || defined(hpux) || defined(_IBMR2)
  1525.     if (ioctl(SHIN, TIOCSLTC, (ioctl_t) & nlc) < 0)
  1526.     return (-1);
  1527. # endif /* OREO || hpux || _IBMR2 */
  1528. #endif /* POSIX */
  1529.     Tty_raw_mode = 0;
  1530. #ifdef BSDSIGS
  1531.     (void) signal(SIGINT, orig_intr);    /* take these again */
  1532. #else
  1533.     (void) sigset(SIGINT, orig_intr);    /* take these again */
  1534. #endif /* BSDSIGS */
  1535.     return (0);
  1536. }
  1537.  
  1538. void
  1539. ResetInLine()
  1540. {
  1541.     Cursor = InputBuf;        /* reset cursor */
  1542.     LastChar = InputBuf;
  1543.     InputLim = &InputBuf[INBUFSIZ - 2];
  1544.     Mark = InputBuf;
  1545.     MetaNext = 0;
  1546.     CurrentKeyMap = CcKeyMap;
  1547.     AltKeyMap = 0;
  1548.     Hist_num = 0;
  1549.     DoingArg = 0;
  1550.     Argument = 1;
  1551. #ifdef notdef
  1552.     LastKill = KillBuf;        /* no kill buffer */
  1553. #endif 
  1554.     LastCmd = F_UNASSIGNED;    /* previous command executed */
  1555.     MacroLvl = -1;        /* no currently active macros */
  1556. }
  1557.  
  1558. static Char *Input_Line = NULL;
  1559. int
  1560. Load_input_line()
  1561. {
  1562.     long    chrs = 0;
  1563.  
  1564.     if (Input_Line)
  1565.     xfree((ptr_t) Input_Line);
  1566.     Input_Line = NULL;
  1567.  
  1568.     if (Tty_raw_mode)
  1569.     return 0;
  1570.  
  1571. #ifdef FIONREAD
  1572.     (void) ioctl(SHIN, FIONREAD, &chrs);
  1573.     if (chrs > 0) {
  1574.     char    buf[BUFSIZ];
  1575.  
  1576.     chrs = read(SHIN, buf, (size_t) min(chrs, BUFSIZ - 1));
  1577. # ifdef __MINT__
  1578.     /* strip out carriage returns */
  1579.     if (chrs > 0) {
  1580.         char *src, *dst;
  1581.         int i;
  1582.  
  1583.         src = dst = buf;
  1584.         for (i = chrs; i > 0; --i) {
  1585.             if (*src == '\r')
  1586.                 --chrs;
  1587.             else
  1588.                 *dst++ = *src;
  1589.             src++;
  1590.         }
  1591.     }
  1592. # endif
  1593.     if (chrs > 0) {
  1594.         buf[chrs] = '\0';
  1595.         Input_Line = Strsave(str2short(buf));
  1596.         PushMacro(Input_Line);
  1597.     }
  1598.     }
  1599. #endif 
  1600.     return chrs > 0;
  1601. }
  1602.  
  1603. /*
  1604.  * Bugfix (in Swedish) by:
  1605.  * Johan Widen
  1606.  * SICS, PO Box 1263, S-163 13 SPANGA, SWEDEN
  1607.  * {mcvax,munnari,cernvax,diku,inria,prlb2,penet,ukc,unido}!enea!sics.se!jw
  1608.  * Internet: jw@sics.se
  1609.  *
  1610.  * (via Hans J Albertsson (thanks))
  1611.  */
  1612.  
  1613. void
  1614. QuoteModeOn()
  1615. {
  1616. #ifndef POSIX
  1617. # ifndef TERMIO
  1618.     struct sgttyb rawb;
  1619. # else
  1620.     struct termio rawb;
  1621. # endif /* TERMIO */
  1622. #else                /* POSIX */
  1623.     struct termios rawb;
  1624. #endif /* POSIX */
  1625.  
  1626.     if (MacroLvl >= 0)
  1627.     return;
  1628.  
  1629. #if defined(TERMIO) || defined(POSIX)
  1630.     rawb = xio;
  1631.     rawb.c_lflag &= ~(ISIG | IEXTEN | PARENB);
  1632.     rawb.c_iflag &= ~(IXON | IXOFF);
  1633. # ifndef POSIX
  1634.     if (ioctl(SHIN, TCSETAW, (ioctl_t) & rawb) < 0)
  1635.     return;
  1636. # else                /* POSIX */
  1637.     if (tcsetattr(SHIN, TCSADRAIN, &rawb) < 0)
  1638.     return;
  1639. # endif /* POSIX */
  1640. #else                /* GSTTYB */
  1641.  
  1642.     rawb = xb;
  1643.     rawb.sg_flags &= ~(CBREAK);
  1644.     rawb.sg_flags |= RAW;
  1645.     if (ioctl(SHIN, TIOCSETN, (ioctl_t) & rawb) < 0)
  1646.     return;
  1647. #endif /* TERMIO || POSIX */
  1648.     Tty_quote_mode = 1;
  1649.     return;
  1650. }
  1651.  
  1652. void
  1653. QuoteModeOff()
  1654. {
  1655.     if (!Tty_quote_mode)
  1656.     return;
  1657.     Tty_quote_mode = 0;
  1658. #if defined(TERMIO) || defined(POSIX)
  1659. # ifndef POSIX
  1660.     if (ioctl(SHIN, TCSETAW, (ioctl_t) & xio) < 0)
  1661.     return;
  1662. # else                /* POSIX */
  1663.     if (tcsetattr(SHIN, TCSADRAIN, &xio) < 0)
  1664.     return;
  1665. # endif /* POSIX */
  1666. #else                /* GSTTYB */
  1667.     if (ioctl(SHIN, TIOCSETN, (ioctl_t) & xb) < 0)
  1668.     return;
  1669. #endif /* !TERMIO && !POSIX */
  1670.     return;
  1671. }
  1672.